package com.ruoyi.usertask.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sms.SmsUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.usertask.domain.SysUserTask;
import com.ruoyi.usertask.service.ISysUserTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户任务表Controller
 * 
 * @author ruoyi
 * @date 2022-10-16
 */
@RestController
@RequestMapping("/usertask/usertask")
public class SysUserTaskController extends BaseController
{
    @Autowired
    private ISysUserTaskService sysUserTaskService;

    /**
     * 查询用户任务表列表
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserTask sysUserTask)
    {
        startPage();
        List<SysUserTask> list = sysUserTaskService.selectSysUserTaskList(sysUserTask);
        return getDataTable(list);
    }




    @GetMapping(value = "/{getSms}")
    public AjaxResult getSms(@PathVariable("id") Integer id)
    {
        System.out.println("ssssss56546");
        System.out.println(SmsUtils.sendSms("13881931979", "ok了"));
        return AjaxResult.success();
    }
    /**
     * 导出用户任务表列表
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:export')")
    @Log(title = "用户任务表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserTask sysUserTask)
    {
        List<SysUserTask> list = sysUserTaskService.selectSysUserTaskList(sysUserTask);
        ExcelUtil<SysUserTask> util = new ExcelUtil<SysUserTask>(SysUserTask.class);
        util.exportExcel(response, list, "用户任务表数据");
    }

    /**
     * 获取用户任务表详细信息
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(sysUserTaskService.selectSysUserTaskById(id));
    }

    /**
     * 新增用户任务表
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:add')")
    @Log(title = "用户任务表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserTask sysUserTask)
    {
        return toAjax(sysUserTaskService.insertSysUserTask(sysUserTask));
    }

    /**
     * 修改用户任务表
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:edit')")
    @Log(title = "用户任务表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserTask sysUserTask)
    {
        return toAjax(sysUserTaskService.updateSysUserTask(sysUserTask));
    }

    /**
     * 删除用户任务表
     */
    @PreAuthorize("@ss.hasPermi('usertask:usertask:remove')")
    @Log(title = "用户任务表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysUserTaskService.deleteSysUserTaskByIds(ids));
    }

}
